namespace CSharpPro._10._13;

public class Demo1
{
    public void TestPrint1()
    {
        {
            Console.WriteLine("请输入第一个整数");
            int x = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入第二个整数");
            int y = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入第三个整数");
            int z = Convert.ToInt32(Console.ReadLine());
            int[] sum = { x, y, z };
            Array.Sort(sum);
            Console.WriteLine("从小到大排序后的结果为：{0}, {1}, {2}", sum[0], sum[1], sum[2]);
        }

    }

    public void TestPrint2()
    {
        static void Main()
        {
            int sum = 0;
            List<int> validNumbers = new List<int>();
            for (int i = 1; i <= 100; i++)
            {
                if (i % 7 != 0 && !ContainsDigitSeven(i))
                {
                    validNumbers.Add(i);
                    sum += i;
                }
            }

            Console.WriteLine("1-100之间所有不是7的倍数且不包含7的数字：");
            Console.WriteLine(string.Join(", ", validNumbers));
            Console.WriteLine($"\n这些数字的总和是：{sum}");
        }

        static bool ContainsDigitSeven(int number)
        {
            if (number == 0)
                return false;
            int temp = Math.Abs(number);
            while (temp > 0)
            {
                if (temp % 10 == 7)
                    return true;
                temp /= 10;
            }

            return false;
        }
    } //作业二

    public void TestPrint3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                Console.Write($"{j}×{i}={i * j}\t");
            }

            Console.WriteLine();
        }
    } //作业三

    public void TestPrint4()
    {
        for (int i = 2; i <= 1000; i++)
        {
            int sum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    sum += j;
                }
            }

            if (sum == i)
            {
                Console.WriteLine(i + "");
            }
        }
    } //作业四

    public void TestPrint5()
    {
        int num;
        while (true)
        {
            Console.Write("请输入一个正整数：");
            if (int.TryParse(Console.ReadLine(), out num) && num > 0)
            {
                break;
            }

            Console.WriteLine("输入无效，请输入一个正整数！");
        }

        int temp = num;
        int digitCount = 0;
        while (temp > 0)
        {
            temp /= 10;
            digitCount++;
        }

        Console.WriteLine($"这个数字是{digitCount}位数");
        Console.Write("逆序打印各位数字：");
        temp = num;
        while (temp > 0)
        {
            int lastDigit = temp % 10;
            Console.Write(lastDigit + " ");
            temp /= 10;
        }

        Console.WriteLine();
    } //作业五

    public void TestPrint6()
    {
        int rows;
        while (true)
        {
            Console.Write("请输入菱形的行数（正整数）：");
            if (int.TryParse(Console.ReadLine(), out rows) && rows > 0)
            {
                break;
            }

            Console.WriteLine("输入无效，请输入一个正整数！");
        }

        PrintDiamond(rows);
    }

    public static void PrintDiamond(int rows)
    {
        int upperRows = (rows + 1) / 2;
        for (int i = 1; i <= upperRows; i++)
        {
            for (int j = upperRows; j > i; j--)
            {
                Console.Write(" ");
            }

            for (int k = 1; k <= 2 * i - 1; k++)
            {
                Console.Write("*");
            }

            Console.WriteLine();
        }

        int lowerRows = rows / 2;
        for (int i = lowerRows; i >= 1; i--)
        {
            for (int j = lowerRows; j >= i; j--)
            {
                Console.Write(" ");
            }

            for (int k = 1; k <= 2 * i - 1; k++)
            {
                Console.Write("*");
            }

            Console.WriteLine();
        }
    } //作业六
}

